
import { MapTypeConfig, PresetStyle, LayerConfig, MapTool, MapControl } from '@/types/map';
declare const AMap: any;
// 地图类型默认配置
export const DEFAULT_MAP_TYPES: MapTypeConfig[] = [
    {
        name: '标准地图',
        type: 'base',
        url: 'https://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
        style:'amap://styles/normal',
        features: ['bg', 'road', 'building', 'point'],
        thumbnail: require('@/assets/image/dixing.jpg'),
    },
    {
        name: '卫星地图',
        type: 'satellite',
        url: 'https://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}',
        style:'amap://styles/satellite',
        features: ['bg', 'point'],
        thumbnail: require('@/assets/image/yingxiang.jpg'),
       
    }
];

// 默认工具配置
export const DEFAULT_TOOLS: MapTool[] = [

];

// 预设样式配置
export const PRESET_STYLES: PresetStyle[] = [
    { name: '默认样式', type: 'default', fill: '#4E87EB', stroke: '#2D5F9E', width: 2, zIndex: 2,opacity: 0 },
    { name: '警示样式', type: 'warning', fill: '#FF4500', stroke: '#8B0000', width: 3, zIndex: 5 ,opacity: 0.7},
    { name: '绿色植被', type: 'green', fill: '#32CD32', stroke: '#228B22', width: 2, zIndex: 3,opacity: 0.7 },
    { name: '道路样式', type: 'road', fill: '#4A4A4A', stroke: '#2D2D2D', width: 8,zIndex: 5,opacity: 0.7},
    { name: '水域样式', type: 'water', fill: '#4E87EB', stroke: '#2D5F9E', width: 2, zIndex: 3,opacity: 0.7},
    { name: '建筑样式', type: 'building', fill: '#FFA500', stroke: '#CC8400', width: 2, zIndex: 4,opacity: 0.7}
];

// 默认图层配置工厂函数
export const createLayerConfig = (): LayerConfig[] => [
    // {
    //     id: 'road',
    //     name: '道路图层',
    //     type: 'road',
    //     visible: true,
    //     layer: null,
    //     style: PRESET_STYLES[4]
    // },
    {
        id: 'work',
        name: '工作图层',
        type: 'work',
        visible: true,
        layer: null,
        style: PRESET_STYLES[0]
    }
];

// 固定工具配置
export const FIXED_TOOLS =  (context: any): MapTool[] => [
    {
        name: 'circle',
        label: '绘制圆形',
        visible: true,
        icon:'circle-icon-32',
        color: '#4E87EB'
    },
    {
        name: 'marker',
        label: '定位标记',
        visible: true,
        icon:'location-icon-32',
        color: '#4E87EB'
    },
    {
        name: 'polygon',
        label: '绘制多边形',
        visible: true,
        icon:'polygon-icon-32',
        color: '#4E87EB'
    },
    {
        name: 'rectangle',
        label: '绘制矩形',
        visible: true,
        icon:'rectangle-icon-32',
        color: '#4E87EB'
    },
    {
        name: 'polyline',
        label: '绘制折线',
        visible: true,
        icon:'polyline-icon-32',
       color: '#4E87EB'
    },
    {
        name: 'startEdit',
        label: '开始编辑',
        icon:'start-edit-icon-32',
        visible: true,
       color: '#4E87EB'
    },
    {
        name: 'cancelEdit',
        label: '停止编辑',
        icon:'cancel-edit-icon-32',
        visible: true,
        color: '#4E87EB'
    }
];

export  const  createControl =(type) => {
    if (typeof AMap === 'undefined') {
        console.warn('AMap is not defined. Cannot create layer:', type);
        return null;
    }
    switch (type) {
        case 'toolbar':
            return new AMap.ToolBar({ //地图缩放插件
                position: {
                    right: '40px',
                    top: '110px'
                }
            })
        case 'control':
            return new AMap.ControlBar({ //控制地图旋转插件
                position: {
                    right: '10px',
                    top: '10px'
                }
            })
        case 'maptype':
                return new AMap.MapType({
                position: {
                    right: '10px',
                    top: '180px'
                }})
        default:
            break;
    }
}

export  function  createLayer(type) {
    switch (type) {
        case 'base':
            return new AMap.TileLayer({
                url: 'https://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
                zIndex: 0,
                visible: true
            })
        case 'building':
           return  new AMap.Buildings({
            zooms: [10, 20],
            zIndex: 10,
            heightFactor: 2, //2倍于默认高度（3D 视图下生效）
        })
        case 'road':
           return  new AMap.TileLayer.RoadNet()
    }
}


// 控件默认配置
export const DEFAULT_CONTROLS: Record<string, MapControl> = {
    searchBar: { visible: true, label: '搜索栏' },
    mapBar: { visible: true, label: '地图样式' },
    toolBar: { visible: true, label: '工具栏' },
    topInfoBar: { visible: true, label: '顶部信息栏' },
    infoBar: { visible: true, label: '底部信息栏' },
    rightPanel: { visible: false, label: '分析栏', activeTabs: ['要素面板', '分析面板','智能搜索面板'] },
    leftMenu: { visible: false, label: '菜单栏', disabled:false },
    mapType:{ visible:true,label:'地图类型', control: null, controlType:"maptype"},
    mapControl:{ visible:true,label:'地图控件', control: null, controlType:"control"},
    mapTool:{ visible:false,label:'地图缩放', control: null, controlType:"toolbar"},
    navBar:{ visible:false,label:'导航栏', control: null}
};

export const MOUSE_TOOL = {
    activeTool: null,
    mouseTool: null,
    circleRadius: 0,
    polygonPoints: [],
    shapes: [],
    currentPosition: null,
    drawingStatus: 'ready', // ready, drawing, placing,
    activeShape: null,      // 当前激活的形状
    activeEditor: null,     // 当前激活的编辑器
    shapesInfo:[]
};
